<?php
class Application_Model_Filter_UserSearch{
    /**
     * 快速搜索
     */
    public $quick;
  
    /**
     * 时间类型
     */
    public $dateselect;
    /**
     * 开始时间
     */
    public $starttime;
    /**
     * 结束时间
     */
    public $endtime;
    /**
     * 国家Id
     */
    public $cityid;
    /**
     * 排序
     */
    public $order;
    /**
     * 登录IP
     */
    public $ip;
    /**
     * 是否联合登录
     */
    public $isUniteLogin;
            
    function getSearchFileds() 
    {
        $where = array();
        $and = '';
        if ($this->quick != '' || $this->starttime != "" || $this->endtime !="" || $this->cityid != "" || $this->ip != "") {

            if($this->quick != ""){
                $and = ' ( ';
                $where[$and . ' nikename like '] = '%' . $this->quick . '%';
                $and = ' or ';
                $where[$and . ' email like '] = '%' . $this->quick . '%';
                $and = ' or ';
                $where[$and . ' phone like '] = '%' . $this->quick . '%';
                $and = ' or ';
                $where[$and . ' storeno like '] = '%' . $this->quick . '%';
                $and = ' ) and ';
                $where[$and . ' 1 = '] = 1;
                $and = " and ";
            }
            if($this->dateselect == "regedit"){
                if($this->starttime != ""){
                    $where[$and." datecreated >= "] = $this->starttime;
                    $and = " and ";
                }
                if($this->endtime != ""){
                    $where[$and." datecreated <= "] = $this->endtime." 23:59:59";
                    $and = " and ";
                }
            } else if($this->dateselect == "login"){ 
                if($this->starttime != ""){
                    $where[$and." lastLogin >= "] = $this->starttime;
                    $and = " and ";
                }
                if($this->endtime != ""){
                    $where[$and." lastLogin <= "] = $this->endtime." 23:59:59";
                    $and = " and ";
                }
            }
            if($this->cityid != "" && $this->cityid != 0){
                $where[$and." cityId = "] = $this->cityid;
                $and = " and ";
            }
            if($this->ip != ""){
                $where[$and. " loginip = "] = $this->ip;
                $and = " and ";
            }
            if($this->isUniteLogin != "") {
                $where[$and. " (userType is null or userType = '0' or userType = '') and "] = 1;
                $and = " and ";
            }
        } else {
            return null;
        }
        return $where;
    }
    
    function getOrderBy()
    {
        if($this->order != ""){
            $order = " cityId ".$this->order;
        } else {
            $order = "id desc";
        }
        return $order;
    }
}
